from aiogram import F
from aiogram_dialog import Dialog, Window
from aiogram_dialog.widgets.kbd import Cancel, ScrollingGroup, Select, Start
from aiogram_dialog.widgets.text import Format

from src.presentation.tg_bot.dialogs.getters.countries import countries_getter
from src.presentation.tg_bot.dialogs.widgets import LocaleText
from src.presentation.tg_bot.states import (
    BuyProxySubscriptionSG,
    ManageProxySubscriptionSG,
    OrderDetailsSG,
    ProxySubscriptionSG,
)

from ...common_handlers import set_country_id
from ...common_windows import get_providers_window
from .handlers import set_proxy_provider

countries_window = Window(
    LocaleText("select-country"),
    ScrollingGroup(
        Select(
            Format("{item.name}"),
            "catselsel",
            lambda country: country.id,
            "countries",
            on_click=set_country_id,
        ),
        width=2,
        height=4,
        id="catsel",
        hide_on_single_page=True,
        when=F["user_language"] == "ru",
    ),
    ScrollingGroup(
        Select(
            Format("{item.name_eng}"),
            "catselsel",
            lambda country: country.id,
            "countries",
            on_click=set_country_id,
        ),
        width=2,
        height=4,
        id="catsel",
        hide_on_single_page=True,
        when=F["user_language"] == "en",
    ),
    Cancel(LocaleText("back-btn")),
    state=ManageProxySubscriptionSG.select_country,
    getter=countries_getter,
)

manage_subscription_dialog = Dialog(
    countries_window, get_providers_window(ManageProxySubscriptionSG, set_proxy_provider)
)
